/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package proyecto2.vista;

import Controlador.Controlador;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import proyecto2.logica.DFA;
import proyecto2.logica.NFA;
import proyecto2.logica.StringGenerator;

/**
 *
 * @author jvm
 */
public class ventana0 extends javax.swing.JFrame {

    /**
     * Creates new form ventana0
     */
    Controlador ctrl;
    private MiPanel a1;
    private JPanel a2;
    private JPanel aU;
    private JPanel aI;
    private JPanel aD;
    private JPanel aD0;
    private JPanel aDS;

    public ventana0() {
        initComponents();
        imagenChk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/proyecto2/vista/img/chk.png")));
        imgWrng.setIcon(new javax.swing.ImageIcon(getClass().getResource("/proyecto2/vista/img/wrng.png")));
        chkImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/proyecto2/vista/img/chk.png")));
        wrngImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/proyecto2/vista/img/wrng.png")));
        this.wrngImg.setVisible(false);
        this.chkImg.setVisible(false);
        this.chkImg.setVisible(false);
        this.imgWrng.setVisible(false);
        this.imagenChk.setVisible(false);
        this.setLocationRelativeTo(null);
        this.recognize.setVisible(false);
        this.recognize.setEnabled(false);
        ctrl = new Controlador();
        auto1 = ctrl.getNFA();
        ctrl.crearAutomataPrueba();
        auto2 = ctrl.getAutomata_prueba();
        this.espacioGramatica.setText(auto1.toDFA().toGrammar().toString());
        creaA1();
        creaA2();
        creaU();
        creaI();
        creaD();
        creaDF();
        creaD0();
        this.setLocationRelativeTo(null);
        this.setTitle("Segundo proyecto: AML(115520842)-JBG(604020813)");
    }

    void creaU() {
        aU = new MiPanel(auto1.toDFA().armaAutomata(auto2.toDFA(), 0));
        aU.setBounds(5, 5, jpDrawIn.getWidth() - 10, jpMixIn.getHeight() - 50);
        jpMixIn.add(aU);
        aU.setVisible(false);
    }

    void creaI() {
        aI = new MiPanel(auto1.toDFA().armaAutomata(auto2.toDFA(), 1));
        aI.setBounds(5, 5, jpDrawIn.getWidth() - 10, jpMixIn.getHeight() - 50);
        jpMixIn.add(aI);
        aI.setVisible(false);
    }

    void creaD() {
        aD = new MiPanel(auto1.toDFA().armaAutomata(auto2.toDFA(), 2));
        aD.setBounds(5, 5, jpDrawIn.getWidth() - 10, jpMixIn.getHeight() - 50);
        jpMixIn.add(aD);
        aD.setVisible(false);
    }

    void creaDF() {
        aDS = new MiPanel(auto1.toDFA().armaAutomata(auto2.toDFA(), 3));
        aDS.setBounds(5, 5, jpDrawIn.getWidth() - 10, jpMixIn.getHeight() - 50);
        jpMixIn.add(aDS);
        aDS.setVisible(false);
    }

    void creaD0() {
        aD0 = new MiPanel(auto2.toDFA().armaAutomata(auto1.toDFA(), 2));
        aD0.setBounds(5, 5, jpDrawIn.getWidth() - 10, jpMixIn.getHeight() - 50);
        jpMixIn.add(aD0);
        aD0.setVisible(false);
    }

    private void creaA1() {
        a1 = new MiPanel(auto1);
        a1.setBounds(10, 10, this.getWidth() - 10, this.getHeight() - 200);
        jpDrawIn.add(a1);
        a1.setVisible(false);

    }

    private void creaA2() {
        a2 = new MiPanel(auto2.toDFA());
        a2.setBounds(10, 10, this.getWidth() - 10, this.getHeight() - 200);
        jpDrawIn.add(a2);
        a2.setVisible(false);
    }

    private void mostrarA1() {
        this.a2.setVisible(false);
        //this.aU.setVisible(false);
        this.a1.setVisible(true);
    }

    private void mostrarA2() {
        this.a1.setVisible(false);
        //this.aU.setVisible(false);
        this.a2.setVisible(true);
    }

    private void mostrarAU() {
        this.aI.setVisible(false);
        this.aU.setVisible(true);
        this.aD.setVisible(false);
        this.aDS.setVisible(false);
        this.aD0.setVisible(false);
    }

    private void mostrarAI() {
        this.aI.setVisible(true);
        this.aU.setVisible(false);
        this.aD.setVisible(false);
        this.aDS.setVisible(false);
        this.aD0.setVisible(false);
    }

    private void mostrarAD() {
        this.aI.setVisible(false);
        this.aU.setVisible(false);
        this.aD.setVisible(true);
        this.aDS.setVisible(false);
        this.aD0.setVisible(false);
    }

    private void mostrarADS() {
        this.aI.setVisible(false);
        this.aU.setVisible(false);
        this.aD.setVisible(false);
        this.aDS.setVisible(true);
        this.aD0.setVisible(false);
    }

    private void mostrarAD0() {
        this.aI.setVisible(false);
        this.aU.setVisible(false);
        this.aD.setVisible(false);
        this.aDS.setVisible(false);
        this.aD0.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor. ctrl = new Controlador();
     * this.jpDrawIn.add( new MiPanel(ctrl.getNFA()));
     * this.jpDrawIn.setBounds(10, 10, this.getWidth() - 10, this.getHeight() -
     * 200); this.jpDrawIn.setVisible(true); this.jpDraw = new
     * MiPanel(ctrl.getNFA()); this.jpDraw.setBounds(10, 10, this.getWidth() -
     * 10, this.getHeight() - 200); this.jpDraw.setVisible(true);
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        all0 = new javax.swing.JPanel();
        automaticos = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jpDraw = new javax.swing.JPanel();
        draw = new javax.swing.JButton();
        combo0 = new javax.swing.JComboBox();
        jpDrawIn = new javax.swing.JPanel();
        jpMix = new javax.swing.JPanel();
        jpMixIn = new javax.swing.JPanel();
        unionBoton = new javax.swing.JButton();
        IntersectionBoton = new javax.swing.JButton();
        differenceBoton = new javax.swing.JButton();
        syDifferenceBoton = new javax.swing.JButton();
        combo1 = new javax.swing.JComboBox();
        combo2 = new javax.swing.JComboBox();
        jpHilera = new javax.swing.JPanel();
        gen = new javax.swing.JButton();
        recognize = new javax.swing.JButton();
        jpHileraIn = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        inputExpresion = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        espacioHilera = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        imagenChk = new javax.swing.JLabel();
        imgWrng = new javax.swing.JLabel();
        jpGramatica = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        inputGramProbar = new javax.swing.JTextField();
        arbolButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        espacioGramatica = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        chkImg = new javax.swing.JLabel();
        wrngImg = new javax.swing.JLabel();
        textoReglas = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        all0.setBackground(new java.awt.Color(0, 0, 0));

        automaticos.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
        automaticos.setForeground(new java.awt.Color(51, 255, 51));
        automaticos.setText("Automa-ticos");

        draw.setBackground(new java.awt.Color(51, 255, 51));
        draw.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        draw.setForeground(new java.awt.Color(0, 0, 0));
        draw.setText("Dibujar");
        draw.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                drawMouseClicked(evt);
            }
        });

        combo0.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"Autómata 1", "Autómata 2"}));
        combo0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo0ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpDrawInLayout = new javax.swing.GroupLayout(jpDrawIn);
        jpDrawIn.setLayout(jpDrawInLayout);
        jpDrawInLayout.setHorizontalGroup(
            jpDrawInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jpDrawInLayout.setVerticalGroup(
            jpDrawInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 379, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jpDrawLayout = new javax.swing.GroupLayout(jpDraw);
        jpDraw.setLayout(jpDrawLayout);
        jpDrawLayout.setHorizontalGroup(
            jpDrawLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDrawLayout.createSequentialGroup()
                .addContainerGap(256, Short.MAX_VALUE)
                .addComponent(combo0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(104, 104, 104)
                .addComponent(draw)
                .addGap(311, 311, 311))
            .addComponent(jpDrawIn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jpDrawLayout.setVerticalGroup(
            jpDrawLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDrawLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpDrawIn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDrawLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(draw)
                    .addComponent(combo0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Dibujar", jpDraw);

        javax.swing.GroupLayout jpMixInLayout = new javax.swing.GroupLayout(jpMixIn);
        jpMixIn.setLayout(jpMixInLayout);
        jpMixInLayout.setHorizontalGroup(
            jpMixInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 636, Short.MAX_VALUE)
        );
        jpMixInLayout.setVerticalGroup(
            jpMixInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 375, Short.MAX_VALUE)
        );

        unionBoton.setBackground(new java.awt.Color(51, 255, 51));
        unionBoton.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N
        unionBoton.setForeground(new java.awt.Color(0, 0, 0));
        unionBoton.setText("U");
        unionBoton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                unionBotonMouseClicked(evt);
            }
        });

        IntersectionBoton.setBackground(new java.awt.Color(51, 255, 51));
        IntersectionBoton.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N
        IntersectionBoton.setForeground(new java.awt.Color(0, 0, 0));
        IntersectionBoton.setText("∩");
        IntersectionBoton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                IntersectionBotonMouseClicked(evt);
            }
        });

        differenceBoton.setBackground(new java.awt.Color(51, 255, 51));
        differenceBoton.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N
        differenceBoton.setForeground(new java.awt.Color(0, 0, 0));
        differenceBoton.setText("-");
        differenceBoton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                differenceBotonMouseClicked(evt);
            }
        });

        syDifferenceBoton.setBackground(new java.awt.Color(51, 255, 51));
        syDifferenceBoton.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N
        syDifferenceBoton.setForeground(new java.awt.Color(0, 0, 0));
        syDifferenceBoton.setText("△");
        syDifferenceBoton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                syDifferenceBotonMouseClicked(evt);
            }
        });

        combo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Autómata 1", "Autómata 2" }));
        combo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo1ActionPerformed(evt);
            }
        });

        combo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Autómata 1", "Autómata 2" }));

        javax.swing.GroupLayout jpMixLayout = new javax.swing.GroupLayout(jpMix);
        jpMix.setLayout(jpMixLayout);
        jpMixLayout.setHorizontalGroup(
            jpMixLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpMixLayout.createSequentialGroup()
                .addGap(163, 163, 163)
                .addComponent(unionBoton)
                .addGap(72, 72, 72)
                .addComponent(IntersectionBoton)
                .addGap(75, 75, 75)
                .addComponent(differenceBoton)
                .addGap(74, 74, 74)
                .addComponent(syDifferenceBoton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpMixLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpMixLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
                .addComponent(jpMixIn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jpMixLayout.setVerticalGroup(
            jpMixLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpMixLayout.createSequentialGroup()
                .addGroup(jpMixLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpMixLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jpMixIn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jpMixLayout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(139, 139, 139)
                        .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(jpMixLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(unionBoton)
                    .addComponent(IntersectionBoton)
                    .addComponent(differenceBoton)
                    .addComponent(syDifferenceBoton))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Mix", jpMix);

        gen.setBackground(new java.awt.Color(51, 255, 51));
        gen.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        gen.setForeground(new java.awt.Color(0, 0, 0));
        gen.setText("Generar");
        gen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                genMouseClicked(evt);
            }
        });

        recognize.setBackground(new java.awt.Color(51, 255, 51));
        recognize.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        recognize.setForeground(new java.awt.Color(0, 0, 0));
        recognize.setText("Reconocer");
        recognize.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                recognizeMouseClicked(evt);
            }
        });

        jLabel1.setText("Expresión Regular");

        inputExpresion.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N

        jLabel2.setText("Hilera");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imgWrng)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(imagenChk)
                .addContainerGap(252, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(imgWrng))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(imagenChk)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jpHileraInLayout = new javax.swing.GroupLayout(jpHileraIn);
        jpHileraIn.setLayout(jpHileraInLayout);
        jpHileraInLayout.setHorizontalGroup(
            jpHileraInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpHileraInLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpHileraInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(espacioHilera, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                    .addComponent(inputExpresion))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jpHileraInLayout.setVerticalGroup(
            jpHileraInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpHileraInLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpHileraInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jpHileraInLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(inputExpresion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(espacioHilera, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(235, Short.MAX_VALUE))))
        );

        javax.swing.GroupLayout jpHileraLayout = new javax.swing.GroupLayout(jpHilera);
        jpHilera.setLayout(jpHileraLayout);
        jpHileraLayout.setHorizontalGroup(
            jpHileraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpHileraLayout.createSequentialGroup()
                .addGap(187, 187, 187)
                .addComponent(gen)
                .addGap(116, 116, 116)
                .addComponent(recognize)
                .addContainerGap(299, Short.MAX_VALUE))
            .addComponent(jpHileraIn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jpHileraLayout.setVerticalGroup(
            jpHileraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpHileraLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpHileraIn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(19, 19, 19)
                .addGroup(jpHileraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gen)
                    .addComponent(recognize))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Hileras", jpHilera);

        jLabel3.setText("Hilera para realizar prueba");

        arbolButton.setBackground(new java.awt.Color(51, 255, 51));
        arbolButton.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        arbolButton.setForeground(new java.awt.Color(0, 0, 0));
        arbolButton.setText(" Árbol Derivación");
        arbolButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                arbolButtonMouseClicked(evt);
            }
        });

        espacioGramatica.setEditable(false);
        espacioGramatica.setColumns(20);
        espacioGramatica.setRows(5);
        jScrollPane1.setViewportView(espacioGramatica);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(wrngImg, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chkImg, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(wrngImg, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                    .addComponent(chkImg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(58, Short.MAX_VALUE))
        );

        textoReglas.setEditable(false);

        javax.swing.GroupLayout jpGramaticaLayout = new javax.swing.GroupLayout(jpGramatica);
        jpGramatica.setLayout(jpGramaticaLayout);
        jpGramaticaLayout.setHorizontalGroup(
            jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpGramaticaLayout.createSequentialGroup()
                .addGroup(jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpGramaticaLayout.createSequentialGroup()
                        .addGap(283, 283, 283)
                        .addComponent(arbolButton)
                        .addGap(0, 352, Short.MAX_VALUE))
                    .addGroup(jpGramaticaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(inputGramProbar))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 531, Short.MAX_VALUE)
                            .addComponent(textoReglas))))
                .addContainerGap())
        );
        jpGramaticaLayout.setVerticalGroup(
            jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpGramaticaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpGramaticaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpGramaticaLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(inputGramProbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
                    .addGroup(jpGramaticaLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(textoReglas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(arbolButton)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Gramática", jpGramatica);

        javax.swing.GroupLayout all0Layout = new javax.swing.GroupLayout(all0);
        all0.setLayout(all0Layout);
        all0Layout.setHorizontalGroup(
            all0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
            .addGroup(all0Layout.createSequentialGroup()
                .addGap(300, 300, 300)
                .addComponent(automaticos)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        all0Layout.setVerticalGroup(
            all0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, all0Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(automaticos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(all0, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(all0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void drawMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_drawMouseClicked
        String s = (String) combo0.getSelectedItem();
        switch (s) {
            case "Autómata 1":
                mostrarA1();
                break;
            case "Autómata 2":
                mostrarA2();
                break;
            default:
                break;
        }
    }//GEN-LAST:event_drawMouseClicked

    private void genMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_genMouseClicked
        String entrada = this.inputExpresion.getText();
        this.imagenChk.setVisible(false);
        this.imgWrng.setVisible(false);
        if (!"".equals(entrada)) {
            this.recognize.setVisible(true);
            this.recognize.setEnabled(true);
            StringGenerator generador = new StringGenerator(this.inputExpresion.getText());
            this.espacioHilera.setText(generador.interpreta());
        } else {
            this.recognize.setVisible(false);
            this.recognize.setEnabled(false);
            JOptionPane.showMessageDialog(null, "Ingrese datos validos para la generación de la hilera.", "Información de funcionamiento",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_genMouseClicked

    private void recognizeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_recognizeMouseClicked
        this.imagenChk.setVisible(false);
        this.imgWrng.setVisible(false);
        if (this.auto1.recognize(espacioHilera.getText())) {
            this.imagenChk.setVisible(true);
            this.imagenChk.setVisible(true);
        } else {
            this.imgWrng.setVisible(true);

        }
    }//GEN-LAST:event_recognizeMouseClicked

    private void combo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_combo1ActionPerformed

    private void combo0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo0ActionPerformed

    }//GEN-LAST:event_combo0ActionPerformed

    private void unionBotonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_unionBotonMouseClicked
        String s1 = (String) combo1.getSelectedItem();
        String s2 = (String) combo2.getSelectedItem();
        if (!s1.equals(s2)) {
            mostrarAU();
        } else {
            JOptionPane.showMessageDialog(null, "Los autómatas no pueden ser iguales.", "Información de funcionamiento",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_unionBotonMouseClicked

    private void IntersectionBotonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_IntersectionBotonMouseClicked
        String s1 = (String) combo1.getSelectedItem();
        String s2 = (String) combo2.getSelectedItem();
        if (!s1.equals(s2)) {
            mostrarAI();
        } else {
            JOptionPane.showMessageDialog(null, "Los autómatas no pueden ser iguales.", "Información de funcionamiento",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_IntersectionBotonMouseClicked

    private void differenceBotonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_differenceBotonMouseClicked
        String s1 = (String) combo1.getSelectedItem();
        String s2 = (String) combo2.getSelectedItem();
        if (!s1.equals(s2)) {
            switch (s1) {
                case "Autómata 1":
                    mostrarAD();
                    break;

                case "Autómata 2":
                    mostrarAD0();
                    break;
            }
        } else {
            JOptionPane.showMessageDialog(null, "Los autómatas no pueden ser iguales.", "Información de funcionamiento",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_differenceBotonMouseClicked

    private void syDifferenceBotonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_syDifferenceBotonMouseClicked
        String s1 = (String) combo1.getSelectedItem();
        String s2 = (String) combo2.getSelectedItem();
        if (!s1.equals(s2)) {
            mostrarADS();
        } else {
            JOptionPane.showMessageDialog(null, "Los autómatas no pueden ser iguales.", "Información de funcionamiento",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_syDifferenceBotonMouseClicked

    private void arbolButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_arbolButtonMouseClicked
        try {
            System.out.println("asdfasdf");
            String obtenido = inputGramProbar.getText();
            if (obtenido.equals("") || obtenido == null) {
                this.chkImg.setVisible(false);
                this.wrngImg.setVisible(true);
                JOptionPane.showMessageDialog(null, "Inserte un valor", "Información de funcionamiento",
                        JOptionPane.ERROR_MESSAGE);

            } else {
                String listaR = auto1.toDFA().toGrammar().obtenerListaDerivacion(obtenido);
                System.out.println(listaR);
                this.textoReglas.setText(listaR);
                this.wrngImg.setVisible(false);
                this.chkImg.setVisible(true);
            }
        } catch (Exception ex) {
            this.chkImg.setVisible(false);
            this.wrngImg.setVisible(true);
            this.textoReglas.setText("No se reconoce la hilera");

        }
    }//GEN-LAST:event_arbolButtonMouseClicked

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(ventana0.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(ventana0.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(ventana0.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(ventana0.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new ventana0().setVisible(true);
//            }
//        });
//    }
//    private DFA creaDFA()
//    {
//        ArrayList<Estado> esta = new ArrayList<>();
//        esta.add(new Estado("X",false,true));
//        esta.add(new Estado("Y",true,false));
//        ArrayList<String> alf = new ArrayList<>();
//        alf.add("0");
//        alf.add("1");
//        ArrayList<Transicion> tr = new ArrayList<>(); 
//        tr.add(new Transicion(new Estado("X",false,true),"0", new Estado("Y",true,false) ));
//        tr.add(new Transicion(new Estado("X",false,true),"1", new Estado("Y",true,false) ));
//        tr.add(new Transicion(new Estado("Y",true,false),"0", new Estado("X",false,true) )); 
//        tr.add(new Transicion(new Estado("Y",true,false),"1", new Estado("Y",true,false) )); 
//        Estado i = new Estado("X",false,true);
//        ArrayList<Estado> fs = new ArrayList<>(); 
//        fs.add(new Estado("Y",true,false)); 
//        return new DFA(esta,alf)
//    }
    private NFA auto1;
    private NFA auto2;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton IntersectionBoton;
    private javax.swing.JPanel all0;
    private javax.swing.JButton arbolButton;
    private javax.swing.JLabel automaticos;
    private javax.swing.JLabel chkImg;
    private javax.swing.JComboBox combo0;
    private javax.swing.JComboBox combo1;
    private javax.swing.JComboBox combo2;
    private javax.swing.JButton differenceBoton;
    private javax.swing.JButton draw;
    private javax.swing.JTextArea espacioGramatica;
    private javax.swing.JTextField espacioHilera;
    private javax.swing.JButton gen;
    private javax.swing.JLabel imagenChk;
    private javax.swing.JLabel imgWrng;
    private javax.swing.JTextField inputExpresion;
    private javax.swing.JTextField inputGramProbar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel jpDraw;
    private javax.swing.JPanel jpDrawIn;
    private javax.swing.JPanel jpGramatica;
    private javax.swing.JPanel jpHilera;
    private javax.swing.JPanel jpHileraIn;
    private javax.swing.JPanel jpMix;
    private javax.swing.JPanel jpMixIn;
    private javax.swing.JButton recognize;
    private javax.swing.JButton syDifferenceBoton;
    private javax.swing.JTextField textoReglas;
    private javax.swing.JButton unionBoton;
    private javax.swing.JLabel wrngImg;
    // End of variables declaration//GEN-END:variables

    private void creaAU(JPanel j, JPanel j1, DFA dfa) {
        j1 = new MiPanel(dfa);
        j1.setBounds(5, 5, j1.getWidth() - 10, j1.getHeight() - 50);
        j.add(j1);
        j1.setVisible(true);
    }
}
